package cn.good.utils;

import cn.good.pojo.User;
import com.alibaba.fastjson.JSON;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * token 验证
 */
@Component
public class TokenVerify {
    @Resource
    private RedisUtil redisUtil;

    /**
     * 验证token是否有效，无效则返回null
     * @return
     */
    public User tokenVerify(String token){
        if(token == null || token.equals("")){
            return null;
        }
        String value = (String) redisUtil.get(token);
        User user = null;
        user = JSON.parseObject(value, User.class);
        return user;
    }
}
